//260
class Solution {
    public int[] singleNumber(int[] nums) {
        if (nums.length == 2) {
            return nums;
        }
        int ab = 0;
        int[] ret = new int[2];
        int len = nums.length;
        for (int i = 0; i < len; i++) {
            ab ^= nums[i];
        }
        ab &= (-ab);
        for (int i = 0; i < len; i++) {
            if ((nums[i] & ab) == 0) {
                ret[0] ^= nums[i];
            }
            else {
                ret[1] ^= nums[i];
            }
        }
        return ret;
    }
}
//268
class Solution {
    public int missingNumber(int[] nums) {
        int len = nums.length;
        int sum = 0;
        int tmp = 0;
        for (int i = 0; i < len; i++) {
            sum += i+1;
            tmp += nums[i];
        }
        return sum - tmp;
    }
}
//371
class Solution {
    public int getSum(int a, int b) {
        int abyh = a ^ b;
        int aby = (a & b) << 1;
        while (aby != 0) {
            a = abyh;
            b = aby;
            abyh = a ^ b;
            aby = (a & b) << 1;
        }
        return abyh;
    }
}
//137
class Solution {
    public int singleNumber(int[] nums) {
        int ret = 0;
        int tmp = 0;
        int len = nums.length;
        if (len == 1) {
            return nums[0];
        }
        for (int i = 0; i < 32; i++) {
            tmp = 0;
            for (int j = 0; j < len; j++) {
                tmp += (nums[j] >> i) & 1;
            }
            tmp %= 3;
            ret |= tmp << i;
        }
        return ret;
    }
}